package com.edge.pbx.view.delay;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;

public class PbxOutputSelectChannelsLayoutWrapper extends ViewGroup {
    public PbxOutputSelectChannelsLayoutWrapper(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        final int width = MeasureSpec.getSize(widthMeasureSpec);
        final int height = MeasureSpec.getSize(heightMeasureSpec);


        View view  = getChildAt(0);
        if (view != null){
            int h = (int) (height* 0.55f);
            int w = (int) (width * 0.85f);


            view.measure(MeasureSpec.makeMeasureSpec(w, MeasureSpec.EXACTLY),
                    MeasureSpec.makeMeasureSpec(h, MeasureSpec.EXACTLY));
        }


        setMeasuredDimension(width, height);


    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        final int width = r - l;
        final int height = b - t;
        View view = getChildAt(0);
        if (view != null){
            int w = view.getMeasuredWidth();
            int h = view.getMeasuredHeight();
            l = ( width - w) /2;
            t = (height - h) /2;
            view.layout(l , t, l + w, t + h);

        }
    }
}
